package com.iary.domain.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.iary.domain.model.block.Block;
import com.iary.domain.model.block.BlockDesc;
import com.iary.domain.model.block.BlockRepository;
import com.iary.domain.model.block.BlockType;
import com.iary.domain.service.BlockService;

@Component
public class BlockServiceImpl implements BlockService {
	
	private BlockRepository blockRepository;
	
	BlockServiceImpl(){
		
	}
	
	@Autowired
	public BlockServiceImpl(BlockRepository blockRepository){
		this.blockRepository = blockRepository;
	}

	@Override
	public List<Block> getBlocksByType(BlockType type) {
		return blockRepository.getBlocksByType(type);
	}

	@Override
	public void save(Block block) {
		blockRepository.insert(block);
	}

	@Override
	public void update(Long id, BlockDesc blockDesc) {
		Block block = new Block(blockDesc);
		block.setId(id);
		blockRepository.update(block);
	}

}
